///sdse_action GfxServer

///sdse_lib OgreMain
///sdse_lin_includeDir /usr/include/OGRE

///sdse_lib CEGUIBase
///sdse_lib CEGUIOgreRenderer
///sdse_lin_includeDir /usr/include/CEGUI

///sdse_lib OIS
///sdse_lin_includeDir /usr/include/OIS

#ifndef GFXSERVER_H
#define GFXSERVER_H

#define OIS_DYNAMIC_LIB

#include "Ogre.h"
#include "OIS.h"
#include "CEGUI.h"
#include "OgreCEGUIRenderer.h"

#include "system/action.h"
#include "system/object.h"

using namespace sde;

class GfxServer : public Action {
private:
    Ogre::Root* root;
    Ogre::Camera* camera;
    Ogre::SceneManager* sceneManager;
    Ogre::RenderWindow* window;
    
    CEGUI::System* guiSystem;
    CEGUI::OgreCEGUIRenderer* guiRenderer;
    CEGUI::WindowManager* guiWindowManager;
    CEGUI::Window* guiSheet;
    
    float frameStart;
    float startTime, lastTime;
    int frameCount;

    bool setup();
    bool configure();
    void chooseSceneManager();
    void createCamera();
    void createViewports();
    void setupResources();
    void loadResources();
    void setupGui();
    
public:
    GfxServer(std::string _type, std::string _name, Object* _object);
    
    void update(VarMap args);
    
    Ogre::RenderWindow* getWindow() {return window;}
    Ogre::SceneManager* getSceneManager() {return sceneManager;}
    
    CEGUI::System* getGuiSystem() {return guiSystem;}
    CEGUI::WindowManager* getGuiWindowManager() {return guiWindowManager;}
    CEGUI::Window* getGuiSheet() {return guiSheet;}
    
    void stop();
    
    static Ogre::Vector3 VectorToOgreVector(Vector3 v);
    static Vector3 OgreVectorToVector(Ogre::Vector3 v);
    static Ogre::Quaternion QuaternionToOgreQuaternion(Quaternion q);
    static Quaternion OgreQuaternionToQuaternion(Ogre::Quaternion q);
};

#endif
